/*
 * @Author: 李环玉 834654733@qq.com
 * @Date: 2023-11-30 17:27:18
 * @LastEditors: 李环玉 834654733@qq.com
 * @LastEditTime: 2023-12-04 09:22:27
 * @FilePath: \koa-server\src\service\admin.service.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

const Admin = require('../model/admin.model')
const UserTag = require('../model/tag.model')
const Tag = require('../model/tag.model')
const Menu = require('../model/menu.model')
const Blog = require('../model/blog.model')
class adminService {
  async getAdminInfo(params){
    const { count, rows } = await Blog.findAndCountAll(
      {
        limit:10,
        offset:10
      },
    )
    const tags = await Tag.findAll()
    const menus = await Menu.findAll()
    await Admin.update({ articleNum:count,tageNum:tags.length,genreNum:menus.length },{
      where:{id:1}
    })
    const json = await Admin.findAll({ include:{model:UserTag} })
    return json
  }
  async getAdminOne(params) {
    const res = await Admin.findOne({
      where:{ userName:params.userName }
    })
    return res
  }
  async update(params){
    const res = await Admin.update(params,{
      where:{   id:params.id }
    })
    return res
  }
  async updatePass(params){
    const res = await Admin.update({ passWord:params.passWord },{
      where:{ userName:params.userName }
    })
    return res
  }
  //查询所有用户
  async getAllAdmin(params){
    const json = await Admin.findAll({})
    return json
  }
}


module.exports = new adminService()